package com.lanou.dllo.vc.dao;

import android.util.Log;

import com.lanou.dllo.vc.greendao.ChatMessage;
import com.lanou.dllo.vc.greendao.ChatMessageDao;

import com.lanou.dllo.vc.greendao.UserInfoDao;

import java.util.List;

/**
 * Created by dllo on 15/12/7.
 */
public class MessageDBhelper implements DBHoldable<ChatMessage> {

    private DaoSingleton instance = DaoSingleton.getInstance();
    private ChatMessageDao messageDao;

    public MessageDBhelper() {
        this.messageDao = instance.getMessageDao();
    }

    @Override
    public void saveData(ChatMessage entities) {
        messageDao.insertOrReplace(entities);
    }

    @Override
    public ChatMessage readDate(String username) {
        return messageDao.queryBuilder().where(ChatMessageDao.Properties.FromUser.eq(username)).list().get(0);
    }

    public List<ChatMessage> readMessage(String username) {

        return messageDao.queryBuilder().where(ChatMessageDao.Properties.FromUser.eq(username)).list();
    }
    public void saveData(List<ChatMessage> entities) {
        messageDao.insertOrReplaceInTx(entities);
    }
}
